package com.tengju.user.infrastructure.persistence.mybatis.mapper.dealer.custom;

import com.tengju.user.infrastructure.persistence.mybatis.dataobject.ArchiveResumeDO;
import org.apache.ibatis.annotations.*;

/**
 * <p>
 * 简历表 Mapper 接口
 * </p>
 */
@Mapper
public interface ArchiveResumeMapper {

    String TEMPLATE_RESULT_MAP = "archive_resume";

    @Select("select * from archive_resume where user_id = #{userId} and deleted = 0")
    @Results(id = TEMPLATE_RESULT_MAP,
            value = {
                    @Result(column = "resume_id", property = "resumeId"),
                    @Result(column = "user_id", property = "userId"),
                    @Result(column = "brand_ids", property = "brandIds"),
                    @Result(column = "self_media", property = "selfMedia"),
                    @Result(column = "community", property = "community"),
                    @Result(column = "company_info", property = "companyInfo"),
                    @Result(column = "channel_experience", property = "channelExperience"),
                    @Result(column = "extra", property = "extra"),
                    @Result(column = "create_time", property = "createTime"),
                    @Result(column = "deleted", property = "deleted")
            })
    ArchiveResumeDO queryByUserId(@Param("userId") long userId);

    @Insert({
            "insert into archive_resume (user_id, brand_ids, self_media, community, company_info, channel_experience, extra, deleted)",
            "values (#{userId}, #{brandIds}, #{selfMedia}, #{community}, #{companyInfo}, #{channelExperience}, #{extra}, 0)"
    })
    @Options(useGeneratedKeys = true, keyProperty = "resumeId")
    int insert(ArchiveResumeDO resume);


    @Update({
            "update archive_resume set brand_ids = #{brandIds}, self_media = #{selfMedia}, " +
                    "community = #{community}, company_info = #{companyInfo}, channel_experience = #{channelExperience}, " +
                    "extra = #{extra}, deleted = 0 where resume_id = #{resumeId}",
    })
    int update(ArchiveResumeDO resume);
}
